package com.zyit.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zyit.dto.HospitalSetDto;
import com.zyit.mapper.HospitalSetMapper;
import com.zyit.pojo.HospitalSet;
import com.zyit.service.HospitalSetService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;

@Service
public class HospitalSetServiceImpl implements HospitalSetService {
    @Autowired
    private HospitalSetMapper hospitalSetMapper;

    @Override
    public List<HospitalSet> findAll() {
        return hospitalSetMapper.selectList(null);
    }

    @Override
    public int del(Long id) {
        return hospitalSetMapper.deleteById(id);
    }

    @Override
    public Page findPage(HospitalSetDto hospitalSetDto) {
        QueryWrapper wrapper = new QueryWrapper();
        if(StringUtils.isNotEmpty(hospitalSetDto.getHosname()))
            wrapper.like("hosname",hospitalSetDto.getHosname());
        if(StringUtils.isNotEmpty(hospitalSetDto.getHoscode()))
            wrapper.eq("hoscode",hospitalSetDto.getHoscode());
        Page page = new Page(hospitalSetDto.getPage(),hospitalSetDto.getLimit());
        return hospitalSetMapper.selectPage(page,wrapper);
    }

    @Override
    public int edit(HospitalSet hospitalSet) {
        return hospitalSetMapper.updateById(hospitalSet);
    }

    @Override
    public int add(HospitalSet hospitalSet) {
        return hospitalSetMapper.insert(hospitalSet);
    }

    @Override
    public int lock(Long id) {
        HospitalSet hs = hospitalSetMapper.selectById(id);
        UpdateWrapper wrapper = new UpdateWrapper();
        wrapper.set("status",hs.getStatus()==0?1:0);
        return hospitalSetMapper.update(wrapper);
    }

    @Override
    public int delBatch(List<Long> ids) {
        return hospitalSetMapper.deleteBatchIds(ids);
    }

}
